package com.weiyuwqj.server.service.invest.impl;

import com.github.pagehelper.PageHelper;
import com.weiyuwqj.api.model.vo.InvestCollectVo;
import com.weiyuwqj.server.service.base.BaseServiceImpl;
import com.weiyuwqj.server.mapper.BusItemCollectMapper;
import com.weiyuwqj.api.service.BusInvestCollectService;
import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.model.BusItemCollect;
import com.weiyuwqj.api.model.vo.BusItemCollectVo;
import com.weiyuwqj.api.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yxw on 2015/12/28.
 */
@Service("investCollectService")
public class BusInvestCollectServiceImp extends BaseServiceImpl<BusItemCollect> implements BusInvestCollectService {
    @Autowired
    BusItemCollectMapper collectMapper;
    /**
     * 显示
     * @return
     */
    @Override
    public PageList getList(Paginator p, Map<String, Object> param) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        List<BusItemCollectVo> list = collectMapper.getList(param);
        return new PageList(list);
    }

    @Override
    public List<BusItemCollectVo> getList(Map<String, Object> param) {
        return collectMapper.getList(param);
    }

    @Override
    public Map<String, Object> getCollectByUserId(Integer userId) {
        return collectMapper.getCollectByUserId(userId);
    }

    //根据用户id查询预期收益、已获得收益
    @Override
    public List<Map<String, Object>> getProfitByUserId(Integer userId) {
        return collectMapper.getProfitByUserId(userId);
    }

    public List<BusItemCollectVo> getExcelList(Map<String, Object> map){
        List<BusItemCollectVo> list = collectMapper.getList(map);
        return list;
    }

    @Override
    public List<Map> getListByUserIdAndTime(Map map) {
        return collectMapper.getListByUserIdAndTime(map);
    }

    @Override
    public List<Map> getMainRepayList(Map map) {
        return collectMapper.getMainRepayList(map);
    }

    @Override
    public List<Map> getListByUserIdAndNow(Map map) {
        return collectMapper.getListByUserIdAndNow(map);
    }

    //后台首页统计今日明日待还金额
    @Override
    public Map countRepayAmount() {
        return collectMapper.countRepayAmount();
    }

    @Override
    public Map statCollect(Map<String, Object> map) {
        return collectMapper.statCollect(map);
    }

    //app昨日收益统计
    @Override
    public BigDecimal countYesterdayIncome(Integer userId) {
        return collectMapper.countYesterdayIncome(userId);
    }

    //本月收益
    @Override
    public BigDecimal countMonthIncome(Integer userId) {
        Map map = new HashMap();
        Date now = new Date();
        map.put("beginDate", DateUtils.formatDate(DateUtils.getMonthStartTime(now)));
        map.put("endDate", DateUtils.formatDate(DateUtils.getNextMonthStartTime(now)));
        map.put("userId", userId);
        return collectMapper.countMonthIncome(map);
    }

    @Override
    public Map checkAccountStat(Map map) {
        return collectMapper.checkAccountStat(map);
    }

    @Override
    public List<InvestCollectVo> getCollectByItemId(Integer itemId) {
        return collectMapper.getCollectByItemId(itemId);
    }

    @Override
    public Map statCollectByItemId(Integer itemId) {
        return collectMapper.statCollectByItemId(itemId);
    }

    @Override
    public List<BusItemCollect> getCollectByItemIdAndUserId(Integer itemId, Integer userId) {
        return collectMapper.getCollectByItemIdAndUserId(itemId,userId);
    }

}
